package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/30 15:08
 **/
public class Day45_9_Offer15_HammingWeight {
    public class Solution {
        // you need to treat n as an unsigned value
        public int hammingWeight(int n) {
            int ans = 0;
            while(n != 0){
                if((n & 1) == 1) ans++;
                n = n >>> 1; // 无符号右移
            }
            return ans;
            // return Integer.bitCount(n);
        }
    }

}